package com.jack.helloworld.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import androidx.annotation.Nullable;
import android.util.AttributeSet;

import com.jack.helloworld.R;
import com.orhanobut.logger.Logger;

public class MyDownloadButton extends androidx.appcompat.widget.AppCompatTextView {

    private Context mContext;

    private float mRadius;
    private int mBgColor;
    private int mBgProgressColor;
    private int mTextColor;
    private int mTextCoveredColor;
    private String mTextNormal;
    private String mTextDownloading;
    private String mTextPause;
    private String mTextFinished;

    private RectF mBgBound;
    private Paint mBgPaint;
    private Paint mBgBorderPaint;
    private Paint mTextPaint;

    public static final int NORMAL = 1;
    public static final int DOWNLOADING = 2;
    public static final int PAUSE = 3;
    public static final int FINISHED = 4;

    public MyDownloadButton(Context context) {
        this(context, null);
    }

    public MyDownloadButton(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyDownloadButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        Logger.d("getMeasureHeight: " + getMeasuredHeight() + " ,getMeasuredWidth: " + getMeasuredWidth());
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyDownloadButton, defStyleAttr, 0);
        mRadius = a.getFloat(R.styleable.MyDownloadButton_radius, getMeasuredHeight() / 2);
        mBgColor = a.getColor(R.styleable.MyDownloadButton_bg_color, Color.BLUE);
        mBgProgressColor = a.getColor(R.styleable.MyDownloadButton_bg_progress_color, Color.YELLOW);
        mTextColor = a.getColor(R.styleable.MyDownloadButton_text_color, Color.BLACK);
        mTextCoveredColor = a.getColor(R.styleable.MyDownloadButton_text_covered_color, Color.WHITE);
        mTextNormal = a.getString(R.styleable.MyDownloadButton_text_normal);
        mTextDownloading = a.getString(R.styleable.MyDownloadButton_text_downloading);
        mTextPause = a.getString(R.styleable.MyDownloadButton_text_pause);
        mTextFinished = a.getString(R.styleable.MyDownloadButton_text_finished);
        a.recycle();

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}
